/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ws;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import org.netbeans.saas.google.GoogleMapService;
import org.netbeans.saas.RestResponse;

/**
 *
 * @author Amaury
 */
public class CallGoogleWS {

    @GET
    @Produces("text/html")
    public static String getGoogleMap(String address) {
        try {
            java.lang.Integer zoom = 15;
            String iframe = "true";

            RestResponse result = GoogleMapService.getGoogleMap(address, zoom, iframe);

            return result.getDataAsString();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return "";
    }

    public double[] getDistance(String adress) {
        try {
            String encoded = URLEncoder.encode(adress, "UTF-8");
            GoogleMapService.GeoCoder coder = new GoogleMapService.GeoCoder(encoded, GoogleMapService.getApiKey());
            GoogleMapService.GeoCode code = coder.invoke();

            double[] tab = new double[2];
            tab[0] = code.getLatitude();
            tab[1] = code.getLongitude();
            return tab;
        } catch (IOException ex) {
            Logger.getLogger(CallGoogleWS.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
}
